#include <atomic>
#include <iostream>
#include <thread>

std::atomic<int> data[5];
std::atomic<bool> sync1(false), sync2(false);


void thread_1() {
    data[0].store(42, std::memory_order_relaxed);
    data[1].store(97, std::memory_order_relaxed);
    data[2].store(17, std::memory_order_relaxed);
    data[3].store(-141, std::memory_order_relaxed);
    data[4].store(2003, std::memory_order_relaxed);

    sync1.store(true, std::memory_order_release);
}

void thread_2() {
    //wait sync1 set, set sync2
    while (!sync1.load(std::memory_order_acquire));
    sync2.store(true, std::memory_order_release);
}

void thread_3() {
    while (!sync2.load(std::memory_order_acquire));

    std::cout << data[0].load(std::memory_order_relaxed) << "\n";
    std::cout << data[1].load(std::memory_order_relaxed) << "\n";
    std::cout << data[2].load(std::memory_order_relaxed) << "\n";
    std::cout << data[3].load(std::memory_order_relaxed) << "\n";
    std::cout << data[4].load(std::memory_order_relaxed) << "\n";
}

int main(int argc, char const *argv[])
{
    std::thread t1(thread_1);
    std::thread t2(thread_2);
    std::thread t3(thread_3);
    
    return 0;
}
